using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CeasarShiftCipherCSharp
{
    public partial class CeasarShiftCipherForm : Form
    {
        private CeasarShiftCipherEngine objCSCipher = new CeasarShiftCipherEngine();

        public CeasarShiftCipherForm()
        {
            InitializeComponent();
        }

        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            string plainText = txtPlaintext.Text.Trim();
            string keyText = txtKey.Text.Trim();

            if (plainText == "" || keyText == "")
                MessageBox.Show("Please fill data on plain text and key box", "Incomplete Data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            else 
            {
                try
                {
                    txtCiphertext.Text = objCSCipher.Encrypt(plainText, Convert.ToInt32(keyText));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void btnDecrypt_Click(object sender, EventArgs e)
        {
            string cipherText = txtCiphertext.Text.Trim();
            string keyText = txtKey.Text.Trim();

            if (cipherText == "" || keyText == "")
                MessageBox.Show("Please fill data on cipher text and key box", "Incomplete Data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            else
            {
                try
                {
                    txtPlaintext.Text = objCSCipher.Decrypt(cipherText, Convert.ToInt32(keyText));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
    }
}